package com.antis.olsl.library.dao;

import com.antis.olsl.library.MyApplication;
import com.antis.olsl.library.bean.UserInfo;
import com.antis.olsl.library.db.UserInfoDao;

import java.util.List;

/**
 * @ProjectName: ATS_OLSL
 * @Package: com.ats.olsl.bean
 * @ClassName: UserInfoControl
 * @Description: java类作用描述
 * @Author: 羊琪
 * @CreateDate: 2020/3/19 10:25
 * @UpdateDate: 2020/3/19 10:25
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class UserInfoControl {

    public static void insert(UserInfo userInfo) {
        MyApplication.getDaoInstant().getUserInfoDao().deleteAll();
        MyApplication.getDaoInstant().getUserInfoDao().insert(userInfo);
    }

    public static void delete() {
        MyApplication.getDaoInstant().getUserInfoDao().deleteAll();
    }

    public static UserInfo getUserInfo() {
        List<UserInfo> userInfos = MyApplication.getDaoInstant().getUserInfoDao().queryBuilder().list();
        return userInfos != null && userInfos.size() > 0 ? userInfos.get(0) : null;
    }

    /**
     * 检查需要修改的对象存在与否
     *
     * @return
     */
    private static boolean checkExist(String userId) {
        UserInfo info = MyApplication.getDaoInstant().getUserInfoDao().queryBuilder().where(UserInfoDao.Properties.UserId.eq(userId)).build().unique();
        return info != null;
    }
}
